function [theta] = apparent_sun_positionST(dn, SolarTime, phi, beta)


%Computes the apparent sun angle (theta). Requires the day number (between
%0 and 365), SolarTime given in 24 hour decimal time, the longitude (phi),
%and the tilt angle of the panel (Beta). 


%%%Hour Angle (w) - angular representation of solar time
    %w - in degrees, w = (solar time (in hours)-12)*15
    
w = (SolarTime-12)*15;

%%%Declination Angle (delta) - the angle between the earth's equatiorial 
%plane and the line joining the center of the sun and the earth
%delta = 23.45 (degrees) * sin((360/365)(dn-81))

delta = (asind((sind(23.45) * sind((360/365)*(dn-81)))));

%%%Altitude (alpha) - complement of the zenith angle (zenith)
% sin_alpha = cosd(phi)*cosd(w)*cosd(delta) + sind(phi)*sind(delta);
% cos_zenith = sin_alpha;
% alpha = asind(sin_alpha);
% zenith = acosd(cos_zenith);


%%%Azimuth Angle (azimuth)
% cos_azimuth = (sind(alpha)*sind(phi) - sind(delta))/((cosd(alpha)*cosd(phi)));
% azimuth = acosd(cos_azimuth);

%%%Apparent Angle of Solar Incidence (theta)
cos_theta = (sind(delta)*sind(phi)*cosd(beta)) -...
    (sind(delta)*cosd(phi)*sind(beta)*cosd(90)) +...
    (cosd(delta)*cosd(phi)*cosd(beta)*cosd(w)) +...
    (cosd(delta)*sind(phi)*sind(beta)*cosd(90)*cosd(w)) +...
    (cosd(delta)*sind(90)*sind(w)*sind(beta));
theta = acosd(cos_theta);
